import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Redirect")
public class Redirect extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf8");
        //注意如果要进行设置重定向，则一定要设置响应报头的状态码为302
        resp.setStatus(302);
        //设置响应报头中的重定向字段新的页面url
        resp.setHeader("Location","https://www.sogou.com");
    }
}
